import React, {createContext, useState} from 'react';
import "./index.scss"

export const ToastContext = createContext();

const ToastContextProvider = ({children}) => {
  const [toastMessage, setToastMessage] = useState(null);

  const showToast = (message) => {
    setToastMessage(message);
  };

  const hideToast = () => {
    setToastMessage(null);
  };

  return (
    <ToastContext.Provider value={{showToast, hideToast}}>
      {children}
      {toastMessage && (
        <div className="toast">{toastMessage}</div>
      )}
    </ToastContext.Provider>
  );
};

export default ToastContextProvider;
